﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class NguyenVatLieuDAO
    {
        public List<NguyenVatLieu_SanPhamDTO> LayDanhSachNguyenVatLieu()
        {
            List<NguyenVatLieu_SanPhamDTO> ds_nvlDto = new List<NguyenVatLieu_SanPhamDTO>();
            try
            {
                string strSQL;
                SqlConnection cn;
                cn = DataProvider.ConnectDB();
                strSQL = "select * from NguyenVatLieu_SanPhamGiaiKhat";

                // Thuc thi chuoi sql
                SqlCommand cmd = new SqlCommand(strSQL, cn);

                SqlDataReader dr = cmd.ExecuteReader();


                while (dr.Read() == true)
                {
                    NguyenVatLieu_SanPhamDTO nvlDto = new NguyenVatLieu_SanPhamDTO();
                    nvlDto.MaNVL = dr.GetInt32(0);
                    nvlDto.Ten = dr.GetString(1);
                    nvlDto.DonViTinh = dr.GetString(2);
                    nvlDto.DonGiaBan = Convert.ToDouble(dr.GetDecimal(3));

                    ds_nvlDto.Add(nvlDto);
                }
                cn.Close();
            }
            catch (Exception ex)
            {

                //
            }

            return ds_nvlDto;

        }
    }
}
